//
//  HDDeclare.m
//  HDSongHuMuseum
//
//  Created by haopeng on 16/8/1.
//  Copyright © 2016年 hengdawb. All rights reserved.
//

#import "HDDeclare.h"
//#import "FMDB.h"
//#import "HDUnitModel.h"
#import <SystemConfiguration/CaptiveNetwork.h>
#import <NetworkExtension/NetworkExtension.h>
#import "UIView+Extension.h"

@interface HDDeclare ()
//@property(strong,nonatomic)FMDatabase *dataBase;

//@property(strong,nonatomic)AFNetworkReachabilityManager *manager;
@end

static HDDeclare *_declare;
@implementation HDDeclare
+(instancetype)shareDeclare
{
    if (!_declare) {
        _declare = [[HDDeclare alloc]init];
    }
    return _declare;
}

-(BOOL)isConnect
{
    return NO;
}

-(void)addNetWorkObserver
{
    //__weak HDDeclare *weakSelf = self;
//    self.manager = [AFNetworkReachabilityManager sharedManager];
    
//    __weak HDDeclare *weakSelf = self;
    
//    [self.manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
//        if (status == AFNetworkReachabilityStatusNotReachable) {
//            [[NSNotificationCenter defaultCenter]postNotificationName:netErrorNoti object:nil];
//            weakSelf.isNetWork = NO;
//        }
//        else if (status == AFNetworkReachabilityStatusUnknown)
//        {
//            weakSelf.isNetWork = NO;
//        }
//        else if (status == AFNetworkReachabilityStatusReachableViaWWAN)
//        {
//            weakSelf.isNetWork = YES;
//        }
//        else if (status == AFNetworkReachabilityStatusReachableViaWiFi)
//        {
//            weakSelf.isNetWork = YES;
//        }
        /*AFNetworkReachabilityStatusUnknown          = -1,
         AFNetworkReachabilityStatusNotReachable     = 0,
         AFNetworkReachabilityStatusReachableViaWWAN = 1,
         AFNetworkReachabilityStatusReachableViaWiFi = 2,*/
//    }];
//    [self.manager startMonitoring];
}

-(instancetype)init
{
    self = [super init];
    if (self) {
//        self.dataBase = [FMDatabase databaseWithPath:self.sql_path];
        
        self.isiBeaconOpen = YES;
        
        if (kScreenHeight < 600) {
            self.isPlus = NO;
        }
        else
        {
            self.isPlus = YES;
        }
        
        self.language = chineseLan;
        self.isMoving  = NO; // 运动传感器
        self.myLocationString = nil;
        [self addNetWorkObserver];
    }
    return self;
}



-(NSString *)wenJuanDiZhi
{
    if ([[self fetchSSIDInfo] isEqualToString:wifiSSID]) {
        _wenJuanDiZhi = neiWangWenJuanDiZhi;
    }
    else
    {
        _wenJuanDiZhi = netWenJuanJieKou;
    }
    
    return _wenJuanDiZhi;
}

-(NSString *)jiaoHuDiZhi
{
    if (!_jiaoHuDiZhi) {
        if ([[self fetchSSIDInfo] isEqualToString:wifiSSID]) {
            _jiaoHuDiZhi = neiWangJiaoHouDiZhi;
        }
        else
        {
            _jiaoHuDiZhi = requestAdress;
        }
    }
    return _jiaoHuDiZhi;
}

-(NSString *)weiPinJie
{
    if (!_weiPinJie) {
        if ([[self fetchSSIDInfo] isEqualToString:wifiSSID]) {
            _weiPinJie = neiWangDownloadAdress;
        }
        else
        {
            _weiPinJie = netDownloadAdress;
        }
    }
    return _weiPinJie;
}

- (NSString *)docPath
{
    return NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
}

-(NSString*)App_catch
{
    return [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex: 0];
}

//-(NSString *)HTTP_Request_URL_Prefix
//{
//    return @"http://192.168.11.14:8002/ServiceApi.asmx";
//}

-(NSString *)myMacAdress
{
    return @"testData";//@"90:FD:61:85:4A:23";//@"38:29:5A:6C:42:77";
}

-(NSString *)shareImagesPath
{
    return [self.catch_path stringByAppendingPathComponent:@"shareImages"];
}

-(NSString *)catch_path
{
    return [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex: 0] stringByAppendingString:@"/resource"];
}

-(NSString *)sql_path
{
    return @"/Users/hdhaoshaopeng/Desktop/huludao.sqlite";//[self.App_catch stringByAppendingString:@"/filemanage.s3db"];
}

-(void)setLanguage:(NSString *)language
{
    _language = language;
    [self chooseLanguage];
}

- (NSString *)fetchSSIDInfo
{
    NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
    id info = nil;
    for (NSString *ifnam in ifs) {
        info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        if (info && [info count]) { break; }
    }
    return [info objectForKey:@"SSID"];
}

#pragma mark - tools Method
//-(NSMutableArray*)giveMeExhibitData
//{
//    NSMutableArray *arr = [NSMutableArray array];
//    
//    if ([self.dataBase open]) {//查询
//        
//        NSString *tempStr = [NSString stringWithFormat:@"SELECT * FROM %@",self.language];
//        FMResultSet * rs = [self.dataBase executeQuery:tempStr];
//        
//        while ([rs next]) {
//            
//            HDExhibitModel *model = [[HDExhibitModel alloc]init];
//
//            model.AutoNum = [rs stringForColumn:@"AutoNum"];
//            model.FileNo = [rs stringForColumn:@"FileNo"];
//            model.Floor = [rs stringForColumn:@"Floor"];
//            model.unitNum = [rs stringForColumn:@"UnitNo"];
//            model.point_x = [rs stringForColumn:@"X"];
//            model.point_y = [rs stringForColumn:@"Y"];
//            
//            [arr addObject:model];
//        }
//        
//        [self.dataBase close];
//    }
//    
//    return arr;
//}

//-(NSMutableArray*)giveMeUnitDataWith:(NSString *)str
//{
//    NSMutableArray *arr = [NSMutableArray array];
//    
//    if ([self.dataBase open]) {//查询
//        
//        NSString *tempStr = [NSString stringWithFormat:@"SELECT * FROM %@",str];
//        FMResultSet * rs = [self.dataBase executeQuery:tempStr];
//        
//        while ([rs next]) {
//            
//            HDUnitModel *model = [[HDUnitModel alloc]init];
//            
//            model.myTitle = [rs stringForColumn:@"Name"];
//            model.fileNo = [rs stringForColumn:@"UnitNo"];
//            model.Floor = [rs stringForColumn:@"floor"];
//            
//            [arr addObject:model];
//        }
//        [self.dataBase close];
//    }
//    
//    return arr;
//}
//
//-(NSMutableArray*)giveMeARDataWith:(NSString *)str
//{
//    NSMutableArray *arr = [NSMutableArray array];
//    
//    if ([self.dataBase open]) {//查询
//        
//        NSString *tempStr = [NSString stringWithFormat:@"SELECT * FROM %@",str];
//        FMResultSet * rs = [self.dataBase executeQuery:tempStr];
//        
//        while ([rs next]) {
//            
//            HDUnitModel *model = [[HDUnitModel alloc]init];
//            
//            model.myTitle = [rs stringForColumn:@"Name"];
//            model.fileNo = [rs stringForColumn:@"ARID"];
//            model.myType = [rs stringForColumn:@"Type"];
//            model.url = [rs stringForColumn:@"URL"];
//            
//            [arr addObject:model];
//        }
//        [self.dataBase close];
//    }
//    
//    return arr;
//}

#pragma mark - 兼容各个语种
-(void)chooseLanguage
{
    if ([_language isEqualToString:chineseLan]) {
        
        self.jieKouYuYan = @"1";
        
        self.downloadOrNotTitle = @"是否开始下载讲解资源";
        self.inPutGroupNum = @"请输入要加入的群组号。";
        self.inPutGroupName = @"请输入群组名称。";
        self.inPutNickName = @"请输入您的新昵称";
        self.comments = @"评论详情";
        self.meiPL = @"当前没有评论。";
        self.banBen = @"版本信息";
        self.loadingStr = @"下载中...";
        self.versionStr = @"广西科技馆V1.0";
        self.beiZhan = @"群组名称已被占用。";
        self.niChengStr = @"昵称";
        self.alert_ok = @"下载";
        self.tiJiao = @"您的评论已提交审核";
        self.tiJiaoStr = @"提交";
        self.zhuTiHuoDong = @"主题活动";
        self.qingWen = @"请问这个展品讲的是什么?";
        self.jiangJieXiaZai = @"讲解资源下载";
        self.yiJian = @"意见反馈";
        self.visitor = @"游客";
        self.wenJuan = @"问卷调查";
        self.jiangJie = @"讲解方式";
        self.canGuan = @"参观";
        self.confirm = @"确定";
        self.alert_cancel = @"取消";
        self.alertTitle = @"提示";
        self.unZiping = @"正在解压";
        self.downloadfailed = @"下载失败";
        self.pleaseDownload = @"请下载资源";
        self.checkNetwork = @"网络连接失败，请检查网络设置";
        self.quitGroup = @"退出群组";
        self.louCengXinHao = @"楼层信号";
        self.shouDao = @"收到";
        self.saoYiSao = @"扫一扫";
        self.root_intro = @"场馆简介";
        self.root_map = @"地图导览";
        self.root_data = @"数字点播";
        self.root_code = @"二维码扫描";
        self.root_list = @"展馆列表";
        self.root_service = @"场馆服务";
        
        self.allowCamera = @"请打开相机权限";
        
        self.gonglue_info = @"攻略";
        self.gonglue_traffic = @"交通路线";
        self.gonglue_envirement = @"周边环境";
        self.gonglue_callUs = @"联系我们";
        self.gonglue_setting = @"设置";
        
        self.inPutExhibit = @"输入编号或名称";
        self.noExhibit = @"没有相应展品";
        self.yongHu = @"用户选择";
        self.yuYanXuanZe = @"语言选择";
        self.pingLunSucceed = @"评论成功！";
        self.canotEmpty = @"输入内容不能为空！";
        self.addGroup = @"加入导览群组";
        self.createGroup = @"创建导览群组";
        
        self.downloadResource = @"资源下载";
        self.deleteResource = @"清除资源";
        self.deleteResourceOrNot = @"是否删除资源";
        self.haveNoResource = @"当前语种暂无资源";
        self.pleaseWaite = @"请等待...";
        self.resourceExist = @"资源已存在";//@"资源已存在，是否重新下载全部资源";
        self.deleteSuccess = @"资源删除成功";
        self.faBiao = @"发 表";
        self.tongBan = @"我的同伴";
        self.zhiHuiStr = @"智慧服务在线";
        self.tuiJianZhiShu = @"推荐指数";
        self.zhanPin = @"展品";
        self.suoZaiStr = @"所在群组";
        self.resourceNotExist = @"当前扫描的展品不存在";
        self.actionSuccess = @"操作成功！";
        self.strTooLong = @"请控制昵称长度";
        self.noLocationMess = @"没有位置信息";
    }
    else if ([_language isEqualToString:englishLan])
    {
        
        self.jieKouYuYan = @"2";
        
        self.downloadOrNotTitle = @"Do you want to start downloading the resources?";
        
        self.loadingStr = @"loading...";
        self.versionStr = @"GuangXi Science Museum V1.0";
        self.beiZhan = @"Group already exist.";
        self.suoZaiStr = @"My Group";
        self.inPutGroupNum = @"Input Group Number";
        self.inPutGroupName = @"Input Group Name";
        self.inPutNickName = @"Please input your new nickname";
        self.comments = @"Comment";
        self.meiPL = @"No comment.";
        self.banBen = @"Version Information";
        self.alert_ok = @"Download";
        self.tiJiao = @"Your comment has been submitted for review";
        self.tiJiaoStr = @"Submit";
        self.zhuTiHuoDong = @"Theme Activities";
        self.qingWen = @"What is this exhibit about?";
        self.jiangJieXiaZai = @"Resource Download";//Audio
        self.yiJian = @"Thoughts";
        self.visitor = @"Visitor";
        self.wenJuan = @"Questionnaire survey";
        self.jiangJie = @"Audio Guide";// Mode
        self.canGuan = @"Visit";
        self.confirm = @"Confirm";
        self.alert_cancel = @"Cancel";
        self.alertTitle = @"Alert";
        self.unZiping = @"Unzipping";
        self.downloadfailed = @"Failed";
        self.pleaseDownload = @"Please download resource";
        self.checkNetwork = @"Network connection failed. Please check the network settings";
        self.quitGroup = @"Quit";
        self.louCengXinHao = @"floor signal";
        self.shouDao = @"Receive";
        self.niChengStr = @"Nickname";
        self.zhiHuiStr = @"Smart Service Online";
        self.saoYiSao = @"Scan";
        self.root_intro = @"Introduction";
        self.root_map = @"Map Guide";
        self.root_data = @"Digital Play";
        self.root_code = @"QR Code";
        self.root_list = @"List";
        self.root_service = @"Service";
        self.gonglue_info = @"Tips";
        self.gonglue_traffic = @"Traffic Information";
        self.gonglue_envirement = @"Surroundings";
        self.gonglue_callUs = @"Contact Us";
        self.gonglue_setting = @"Settings";
        
        self.inPutExhibit = @"Input number or name";
        self.noExhibit = @"No Exhibition";
        self.yongHu = @"User Selection";
        self.yuYanXuanZe = @"Language";
        self.pingLunSucceed = @"Comment on success";
        self.canotEmpty = @"Input content cannot be empty";
        self.addGroup = @"Add Group";
        self.createGroup = @"Create Group";
        
        self.allowCamera = @"Please allow camera usable access";
        
        self.downloadResource = @"Download Resource";
        self.deleteResource = @"Eliminate Resources";
        self.deleteResourceOrNot = @"Are you sure to delete the Resource";
        self.haveNoResource = @"There have no resource";
        self.pleaseWaite = @"Wait...";
        self.resourceExist = @"Resource exist";//@"Resource exist,download again?";
        self.deleteSuccess = @"Delete success!";
        self.strTooLong = @"please short nickname length";
        self.noLocationMess = @"No location message";
        self.resourceNotExist = @"Exhibit does not exist";
        self.actionSuccess = @"Success!";
        self.faBiao = @"Publish";
        self.tongBan = @"My Companion";
        self.tuiJianZhiShu = @"Rating";//Recommendation
        self.zhanPin = @"Exhibition";
    }
    else if ([_language isEqualToString:russiaLan])
    {
        self.downloadOrNotTitle = @"ガイドリソースを更新";
        self.alert_ok = @"ダウンロード";
        self.confirm = @"確定";
        self.alert_cancel = @"取消し";
        self.alertTitle = @"ヒント";
        self.unZiping = @"纸が";
        self.downloadfailed = @"ダウンロードに失败し";
        self.pleaseDownload = @"音声ガイドリソースをダンロードしてください";
        self.checkNetwork = @"ネットエラー。ネット設置をチェックしてください";
        
        self.root_intro = @"博物館のご案内";
        self.root_map = @"地図ガイド";
        self.root_data = @"オンデマンド";
        self.root_code = @"二次元コード";
        self.root_list = @"リストガイド";
        self.root_service = @"サービス";
        
        self.gonglue_info = @"観覧の手引き";
        self.gonglue_traffic = @"交通情報";
        self.gonglue_envirement = @"周囲の状況";
        self.gonglue_callUs = @"お問い合わせ";
        self.gonglue_setting = @"設置";
        
        self.inPutExhibit = @"展示品の番号と名称をご入力ください";
        self.noExhibit = @"この番号がありません";
        
        self.downloadResource = @"リソースダンロード";
        self.deleteResource = @"リソース削除";
        self.deleteResourceOrNot = @"当該言語のリソースを全部削除しますか";
        self.haveNoResource = @"当該言語はリソースがありません";
        self.pleaseWaite = @"暫くお待ちください...";
        self.resourceExist = @"展示品リソースがあってもう一度全部ダンロードしますか";
        self.deleteSuccess = @"当該言語のリソースを削除しました";
        
        self.resourceNotExist = @"当面の走査の展示品は存在しません";
    }
}

@end
